//
//  NSObject+IGUrlAppendPara.m
//  jingdongfang
//
//  Created by BOE on 2017/8/10.
//  Copyright © 2017年 ZhiYu Hao. All rights reserved.
//

#import "NSObject+IGUrlAppendPara.h"

@implementation NSObject (IGUrlAppendPara)

+ (NSString *)urlStringWithOriginUrlString:(NSString *)originUrl appendParameters:(NSDictionary *)parameters {

    NSMutableString *muOriginUrl = [NSMutableString stringWithString:originUrl];
    
    NSArray *keys = parameters.allKeys;
    NSInteger count = keys.count;

    for (int i = 0; i < count; i++) {
        NSString *key = keys[i];
        NSString *value = parameters[key];
        
        if (0 == i) {
            [muOriginUrl appendString:@"?"];
        }
        
        [muOriginUrl appendFormat:@"%@=%@", key, value];
        
        if (count - 1 != i) {
            [muOriginUrl appendString:@"&"];
        }
    }
    
    return muOriginUrl;
}

@end
